<?php
namespace app\index\controller;
use app\common\controller\Classes;
use app\common\controller\Message;
use think\Controller;
use app\common\controller\Article;

class Index extends Controller
{
//    首页展示
    public function index()
    {
        $article = new Article();
        $count = new CountVisitor();
//      访客记录
        $count->visitor();
        $this->assign("title", "护蕾行动 | 首页")
            ->assign("articles1", $article->selectLimitArticle(1,3))
            ->assign("articles2",$article->selectLimitArticle(2,3))
            ->assign("articles3",$article->selectLimitArticle(3,3));
        return $this->fetch("index");
//        var_dump($data);
    }

//    留言板
    public function showMessage()
    {
        $messages = new Message();
        $this->assign("title", "护蕾行动 | 留言板")
            ->assign("message",$messages->selectAllMessage(1));
        return $this->fetch("index/message");
    }

//    关于我们
    public function showAboutMe()
    {
        $this
//            ->assign("content", Db::table('b_admin')
//                            ->where('admin_id',1)
//                            ->find()['admin_content'])
        ->assign("title", "护蕾行动 | 关于我们");
        return $this->fetch("index/aboutme");
    }

    public function showNews()
    {
        $article = new Article();
        $this->assign("title", "护蕾行动 | 新闻动态")
            ->assign("news", $article->selectAllArtAndClaPage(4,8));
        return $this->fetch("index/news");
    }

    public function showCargo()
    {
        $article = new Article();
        $this->assign("title", "护蕾行动 | 干货分享")
            ->assign("cargos",  $article->selectArticleLimit(5,50));
        return $this->fetch("index/cargo");
    }

    public function showTreesHole()
    {
        $article = new Article();
        $this->assign("title", "护蕾行动 | 树洞社区")
            ->assign("articles6", $article->selectAllArtAndClaPage(6,6))
            ->assign("articles7", $article->selectAllArtAndClaPage(7,6));
        return $this->fetch("index/treeshole");
    }


    public function showDetails($articleId)
    {
        $articles = new Article();
        $data = $articles->selectArtAndClaFromClaId($articleId);
        $this->assign("title", "护蕾行动 | ".$data["article_name"])
            ->assign("article", $data)
            ->assign("next",$articles->selectNextForTimeById($articleId))
            ->assign("last", $articles->selectLastForTimeById($articleId));
//        var_dump($articles->selectNextForTimeById($articleId));
        return $this->fetch("index/details");
    }

    public function showList($listId)
    {
        $article = new Article();
        $classes = new Classes();
        $this->assign("title", "护蕾行动 | ".$classes->selectClassFromId($listId)['class_name'])
            ->assign("articles", $article->selectAllArtAndClaPage($listId,6));
        return $this->fetch("index/list");
    }


    /*测试接口*/
    public function visitorControl(){
        $count_visitor = new CountVisitor();
        return $count_visitor->visitor();
    }

}
